using System;
using System.Collections.Generic;
using System.Text;

namespace GeoPlugIn
{
    //------------------------------------------------------------------------
    #region Base CSV class
    
    public class CsvBase
    {
        protected string name;
        protected string[] Items;
        protected int nbColumns;
        protected char separator = '\t';

        //Properties common to all
        public string Id;
        public string Code;
        public string ShortTitle;
        public string OfficialTitle;
        public string SysUpdateDt;

        // C'tor
        protected CsvBase(string name, int nbCol, string csvRow)
        {
            // Pre conditions
            if (string.IsNullOrEmpty(csvRow))
                throw new ApplicationException("Unexpected. Empty CSV row delivered.");

            this.name = name;
            nbColumns = nbCol;

            Items = csvRow.Split(separator);

            // Ensure correct number of columns
            if (Items.Length != nbColumns)
                throw new ApplicationException(string.Format(
                    "Unexpected. Invalid number of fields for {0} CSV row delivered. Expected:{1}, Found:{2}",
                    name, nbColumns, Items.Length));

        }
    }
    #endregion

    //------------------------------------------------------------------------
    #region Canton CSV class

    public class CsvCanton : CsvBase
    {
        public CsvCanton(string csvRow) : base("Canton", 4, csvRow)
        {
            // Fetch Info into properties
            Code            = Items[0].Trim();
            ShortTitle      = Items[1].Trim();
            OfficialTitle   = Items[2].Trim();
            SysUpdateDt     = Items[3].Trim();

            //Clear no more usage
            Items = null;
        }
    }

    #endregion

}
